package com.example.localizadorv4;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class Tag1 extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_tag1);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.tag1, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	/******* Create SharedPreferences *******/
   public void shared(){
   SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE); 
   Editor editor = pref.edit();


/**************** Storing data as KEY/VALUE pair *******************/

   editor.putString("key_name5", "string value");  // Saving string
   editor.putInt("tag1_name", 2);        // Saving integer
   editor.putInt("tag1_name2", 2);        // Saving integer
   editor.putInt("tag1_name2", 2);        // Saving integer
   editor.putInt("tag1_name2", 2);        // Saving integer
   editor.putFloat("tag1_name3", 2);    // Saving float
    
   // Save the changes in SharedPreferences
   editor.commit(); // commit changes


/**************** Get SharedPreferences data *******************/

//If value for key not exist then return second param value - In this case null

   pref.getBoolean("key_name1", (Boolean) null);         // getting boolean
   pref.getInt("key_name2", (Integer) null);             // getting Integer
   pref.getFloat("key_name3", (Float) null);           // getting Float
   pref.getLong("key_name4", (Long) null);            // getting Long
   pref.getString("key_name5", null);          // getting String




/************ Deleting Key value from SharedPreferences *****************/

   editor.remove("key_name3"); // will delete key key_name3
   editor.remove("key_name4"); // will delete key key_name4
    
   // Save the changes in SharedPreferences
   editor.commit(); // commit changes
   
/************ Clear all data from SharedPreferences *****************/  

    editor.clear();
    editor.commit(); // commit changes
	 }
}

	

